package com.beans;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
public class UserBeans {

    //对象注入(属性注入)

    @Autowired
    private UserController userController;

    public void func() {
        userController.sayHi();
    }
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)  //多例模式(设置bean的作用域)(spring中bean默认单例)
    @Bean(name = {"user1"})
    public User user1() {
        User user = new User();
        user.setId(1);
        user.setName("陶俊臣");
        return user;
    }
}
